package com.zj.config;

import com.fasterxml.jackson.annotation.JsonInclude;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置类,解决json序列化问题
 * 对jackson生成的json字符串进行配置
 * 2.如果属性为null,则不序列化
 */
@Configuration
public class JsonConfig {
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer objectMapper() {
        return builder -> builder.
                serializationInclusion(JsonInclude.Include.NON_EMPTY);  //设置序列化方法,如果属性为空,则不序列化
    }
}
